<?php

class Module_Mediate_Case extends Module_BaseModule
{
    use Lib_BaseTraitsModule;
    private static $obj = null;
    private $model = null;
    // 案件系统状态
    public static $sysStatusArr = array(
        1 => '正常',
        2 => '撤案',
        3 => '拒绝调解',
        4 => '删除',
    );
    public static $closeReason = array(
        1 => '接受提交',
        2 => '调解不成',
        3 => '不适宜调解',
        4 => '无法联系',
    );
    public static $disputeType = array(
        1 => '借款合同纠纷',
        2 => '信用卡纠纷',
        3 => '保险纠纷',
        4 => '其他合同纠纷',
    );
    public static $caseType = array(
        1 => '纯调案件',
        2 => '诉保案件',
        3 => '裁执案件',
    );
    public static $customLabel = array(
        99 => '无',
        1 => '可联案件',
        2 => '半联案件',
        3 => '失联案件',
    );
    public static $customGrade = array(
        99 => '无',
        1 => '还款/意向还款',
        2 => '呼叫受限',
        3 => 'C级用户',
        4 => 'D级用户',
        5 => 'E级用户',
    );

    // 案件节点状态对应关系
    public static $caseStatusArr = array(
        'case_audit' => '案件审核',
        'case_allocate' => '案件分配',
        'case_mediate' => '案件调解',
        'mediate_audit' => "案件调解审核",
        'close_case' => "结案",
    );
    // 案件调解结果状态
    public static $mediateResult = array(

//        'no_answer'=>"无人接听",
//        'Willing_capable'=>'有意愿有能力',
//        'Willing_incapable'=>'有意愿无能力',
//        'reluctant_capable'=>'无意愿有能力',
//        'reluctant_incapable'=>'无意愿无能力',
//        'empty_number'=>'空号',
//        'shutdown'=>'停机',
//        'not_myself'=>'非本人',
//        'call_failed'=>'呼出失败',
//        'not_available'=>'无法接通',
//        'ambiguity_myself'=>'不明确是否本人',
//        'not_speaking'=>'接通不说话,秒挂',
//        'risk_case'=>'风险案件',
//        'no_results' => '未沟通',
        'no_answer'=>" 无人接听",
        'achieve_plan'=>'达成方案',
        'oral_agreement'=>' 口头协议或部分还款',
        'intentional_repayment'=>'意向还款',
        'in_negotiations'=>'洽谈中',
        'negative_attitude'=>'态度消极',
        'not_available'=>'无法接通',
        'call_exhalation'=>'呼出受限',
        'call_failed'=>'呼出失败',
        'ambiguity_myself'=>'不明确是否本人',
        'not_speaking'=>'接通不说话,秒挂',
        'empty_number'=>'空号',
        'shutdown'=>'停机',
        'not_myself'=>'非本人',
        'no_results' => '未沟通',
    );

    // 案件调解状态
    public static $mediateStatus = array(
        'first_mediate' => '首次调解',
        'in_mediate' => '调解中',
        'finish_mediate' => '完成调解',
        'reject_mediate' => '调解驳回',
    );
    // 还款
    public static $repayStatusArr = array(
        'no_repay' => '未还款',
        'wait_repay' => '待还款',
        'break_repay' => '失约还款',
        'keep_repay' => '守约还款中',
        'finish_repay' => '完成还款',
        'cancel_repay' => '作废还款',
    );
    //还款计划详情表状态
    public static $planStatusArr = array(
        'keep_plan' => '未还款',
        'wait_plan' => '待审核',
        'reject_plan' => '驳回审核',
        'finish_plan' => '审核通过',
        'cancel_repay' => '作废还款',
    );
    //今日联系状态
    public static $todayContactStutus = array(
        1 => '未联系',
        2 => '未接通',
        3 => '已联系',
    );


    // 案件节点状态对
    public static $NoteStatusArr = array(
        'case_save' => '案件入库',
        'case_audit' => '录入案件审核',
        'case_allocate_mediator' => '分配案件到调解员',
        'case_allocate_organ' => '分配案件到调解部门',
        'mediate_audit' => '调解审核',
        'submit_mediate_audit' => '提交调解审核',
        'case_transfer' => '案件转交',
        'update_expire_time' => '更新案件到期时间',
        'replay_no_show' => '还款失约',
        'case_withdraw' => '撤案',
        'update_case_attr' => '修改案件属性',
    );
    public static $mediatefield = [
        'id' => [
            'name' => '案件ID',
            'default' => 1,
        ],
        'assetsId' => [
            'name' => '资产方',
            'default' => 1,
            'change' => 'assets',
        ],
        'mediationNum' => [
            'name' => '调解号',
            'default' => 1,
        ],
        'litigantName' => [
            'name' => '当事人',
            'default' => 1,
        ],
        'meidate' => [
            'name' => '联系',
            'default' => 1,
            'meidate' => 1,
        ],
        'customLabel' => [
            'name' => '客户标签',
            'default' => 1,
            'change' => 'customLabel',
        ],
        'customGrade' => [
            'name' => '客户等级',
            'default' => 1,
            'change' => 'customGrade',
        ],
        'caseType' => [
            'name' => '案件类型',
            'default' => 1,
            'change' => 'caseType',
        ],
        'batchName' => [
            'name' => '批次名称',
            'default' => 1,
        ],
        'mediateResult' => [
            'name' => '调解结果',
            'default' => 1,
            'change' => 'mediateResult',
        ],
        'loanPlatform' => [
            'name' => '借款平台',
            'default' => 1,
        ],
        'loanTerm' => [
            'name' => '借款期限/月',
            'default' => 1,
        ],
        'debtTotal' => [
            'name' => '欠款总额',
            'default' => 1,
        ],
        'claimAmount' => [
            'name' => '诉求金额',
            'default' => 1,
        ],
        'overdueDate' => [
            'name' => '逾期日期',
            'default' => 1,
            'time' => 1,
        ],
        'lastCallTime' => [
            'name' => '最后一次呼叫时间',
            'default' => 1,
            'time' => 1,
        ],
        'mediationOrganId' => [
            'name' => '调解组',
            'default' => 0,
            'change' => 'mediationOrgan',
        ],
        'repayStatus' => [
            'name' => '还款状态',
            'default' => 0,
            'change' => 'repayStatus',
        ],
        'contractNo' => [
            'name' => '合同号',
            'default' => 0,
        ],
        'loanRate' => [
            'name' => '借款利率',
            'default' => 0,
        ],
        'combinRate' => [
            'name' => '综合利率',
            'default' => 0,
        ],
        'debtAmount' => [
            'name' => '欠还本金',
            'default' => 0,
        ],
        'debtInte' => [
            'name' => '欠还利息',
            'default' => 0,
        ],
        'putoutDate' => [
            'name' => '放款日期',
            'default' => 0,
        ],
        'maturityDate' => [
            'name' => '到期日期',
            'default' => 0,
        ],
        'loanAmount' => [
            'name' => '借款金额',
            'default' => 0,
        ],
        'repayAmount' => [
            'name' => '已还本金',
            'default' => 0,
        ],
        'repayInte' => [
            'name' => '已还利息',
            'default' => 0,
        ],
        'repayTotal' => [
            'name' => '已还总额',
            'default' => 0,
        ],
        'debtTargetDate' => [
            'name' => '欠款暂记日',
            'default' => 0,
            'time' => 1,
        ],
        'allocateTime' => [
            'name' => '分案日期',
            'default' => 0,
            'time' => 1,
        ],
        'entrustExpireTime' => [
            'name' => '委托到期时间',
            'default' => 0,
            'time' => 1,
        ],
        'addTime' => [
            'name' => '案件入库时间',
            'default' => 0,
            'time' => 1,
        ],
        'batshId' => [
            'name' => '案件标识号',
            'default' => 0,
            'time' => 1,
        ],
        'importRecordId' => [
            'name' => '导入批次号',
            'default' => 0,
            'time' => 1,
        ],
    ];
    public static $contactfield = [
        'id' => [
            'name' => '案件ID',
            'default' => 1,
        ],
        'assetsId' => [
            'name' => '资产方',
            'default' => 1,
            'change' => 'assets',
        ],
        'mediationNum' => [
            'name' => '调解号',
            'default' => 1,
        ],
        'litigantName' => [
            'name' => '当事人',
            'default' => 1,
        ],
        'nextTime' => [
            'name' => '计划联系时间',
            'default' => 1,
            'time' => 1,
        ],
        'meidate' => [
            'name' => '联系',
            'default' => 1,
            'meidate' => 1,
        ],
        'customLabel' => [
            'name' => '客户标签',
            'default' => 1,
            'change' => 'customLabel',
        ],
        'customGrade' => [
            'name' => '客户等级',
            'default' => 1,
            'change' => 'customGrade',
        ],
        'caseType' => [
            'name' => '案件类型',
            'default' => 1,
            'change' => 'caseType',
        ],
        'batchName' => [
            'name' => '批次名称',
            'default' => 1,
        ],
        'mediateResult' => [
            'name' => '调解状态',
            'default' => 1,
            'change' => 'mediateResult',
        ],
        'loanPlatform' => [
            'name' => '借款平台',
            'default' => 1,
        ],
        'loanTerm' => [
            'name' => '借款期限/月',
            'default' => 1,
        ],
        'debtTotal' => [
            'name' => '欠款总额',
            'default' => 1,
        ],
        'claimAmount' => [
            'name' => '诉求金额',
            'default' => 1,
        ],
        'overdueDate' => [
            'name' => '逾期日期',
            'default' => 1,
            'time' => 1,
        ],
        'lastCallTime' => [
            'name' => '最后一次呼叫时间',
            'default' => 1,
            'time' => 1,
        ],
        'mediationOrganId' => [
            'name' => '调解组',
            'default' => 0,
            'change' => 'mediationOrgan',
        ],
        'repayStatus' => [
            'name' => '还款状态',
            'default' => 0,
            'change' => 'repayStatus',
        ],
        'contractNo' => [
            'name' => '合同号',
            'default' => 0,
        ],
        'loanRate' => [
            'name' => '借款利率',
            'default' => 0,
        ],
        'combinRate' => [
            'name' => '综合利率',
            'default' => 0,
        ],
        'debtAmount' => [
            'name' => '欠还本金',
            'default' => 0,
        ],
        'debtInte' => [
            'name' => '欠还利息',
            'default' => 0,
        ],
        'putoutDate' => [
            'name' => '放款日期',
            'default' => 0,
        ],
        'maturityDate' => [
            'name' => '到期日期',
            'default' => 0,
        ],
        'loanAmount' => [
            'name' => '借款金额',
            'default' => 0,
        ],
        'repayAmount' => [
            'name' => '已还本金',
            'default' => 0,
        ],
        'repayInte' => [
            'name' => '已还利息',
            'default' => 0,
        ],
        'repayTotal' => [
            'name' => '已还总额',
            'default' => 0,
        ],
        'debtTargetDate' => [
            'name' => '欠款暂记日',
            'default' => 0,
            'time' => 1,
        ],
        'allocateTime' => [
            'name' => '分案日期',
            'default' => 0,
            'time' => 1,
        ],
        'entrustExpireTime' => [
            'name' => '委托到期时间',
            'default' => 0,
            'time' => 1,
        ],
        'addTime' => [
            'name' => '案件入库时间',
            'default' => 0,
            'time' => 1,
        ],
        'importRecordId' => [
            'name' => '案件批次号',
            'default' => 0,
        ],
        'batshId' => [
            'name' => '导入批次号',
            'default' => 0,
        ],
    ];
    public static $planfield = [
        'id' => [
            'name' => '计划ID',
            'default' => 0,
        ],
        'mediationOrganId' => [
            'name' => '调解组',
            'default' => 0,
            'change' => 'mediationOrgan',
        ],
        'assetsId' => [
            'name' => '资产方',
            'default' => 0,
            'change' => 'assets',
        ],
        'litigantName' => [
            'name' => '当事人',
            'default' => 1,
        ],
        'mediatorName' => [
            'name' => '调解员',
            'default' => 1,
        ],
        'caseId' => [
            'name' => '案件id',
            'default' => 1,
        ],
        'meidate' => [
            'name' => '联系',
            'default' => 1,
            'meidate' => 1,
        ],
        'status' => [
            'name' => '还款状态',
            'default' => 1,
            'change' => 'repayStatus',
        ],
        'repayAmount' => [
            'name' => '还款总额',
            'default' => 1,
        ],
        'repaidAmount' => [
            'name' => '已还金额',
            'default' => 1,
        ],
        'numberOfPayments' => [
            'name' => '还款期数',
            'default' => 1,
        ],
        'numberOfRepaid' => [
            'name' => '已还期数',
            'default' => 1,
        ],
        'repaymentDate' => [
            'name' => '每月还款日',
            'default' => 1,
        ],
        'addTime' => [
            'name' => '创建时间',
            'default' => 1,
            'time' =>1
        ],

    ];

    //根据案件ids修改案件信息
    public function saveByIds($updateDta, $ids,$where=[])
    {
        return $this->model->saveByIds($updateDta, $ids,$where);
    }

    /**
     * 封闭构造.
     */
    public function __construct()
    {
        $this->model = new Model_Mediate_Case();
    }

    /**
     * 单例获取
     * 保证一条进程只产生一个Module对象
     *
     * @return Module_Mediate_Case
     */
    public static function getInstance()
    {
        if (empty(self::$obj)) {
            self::$obj = new self();
        }

        return self::$obj;
    }

    /*
   **添加
   * @param $insertdata
   * @return mixed
   */
    public function insert($case,$litigant,$case_operation_log_arr=[],$attach=[])
    {
        return $this->model->insert($case,$litigant,$case_operation_log_arr,$attach);
    }

    /**
     * 修改数据.
     */
    public function update($update, $id)
    {
        return $this->model->update($update, $id);
    }

    /**
     *  分页查询.
     */
    public function countBySearch($search)
    {
        if (empty($search)) {
            return false;
        }

        return $this->model->countBySearch($search);
    }


    /**
     * @desc 通过id查看案件详情
     *
     * @param int $id
     *
     * @return array
     */
    public function getInfoById($id = 0, $clear = false)
    {
        if (!$id) {
            return false;
        }

        return $this->model->getInfoById($id, $clear);
    }

    //根据省份证号码获取相关案件
    public function getCaseIdByName($name){
        return $this->model->getCaseIdByName($name);
    }

    //通过变化的条件获取数据
    public function getDataByChangeWhere($where)
    {
        return $this->model->getDataByChangeWhere($where);
    }


    //根据id修改案件状态并且添加案件日志
    public function updateStatusAddLogById($case_info, $log_info = array())
    {
        return $this->model->updateStatusAddLogById($case_info, $log_info);
    }

    //每天修改打电话状态
    public function updateTodayContactStutus()
    {
        return $this->model->updateTodayContactStutus();
    }
    //每天跟新计划沟通时间
    public function updateNextTime()
    {
        return $this->model->updateNextTime();
    }

}
